<template>
	<view class="wraptop" style="min-height: 100vh;">
		<view class="xhmc">
			<picker @change="bindPickerChange" :value="index" range-key="text" :range="array">
				<view class="uni-input">{{array[index].text}}</view>
			</picker>
		</view>
		<view class="content_input">
			<input type="number" maxlength="16" value="" v-model="yhk" class="input_cot" style="text-align: left;border-radius: 40px;background-color: rgb(250,250,250);"
			 placeholder="添加银行卡" />
		</view>
		<view class="btn" @click="regup">
			<text>完成</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				yhk:'',
				index: 0,
				array: [{
					text: '请选择银行名称'
				}],
				text:''
			}
		},
		onLoad: function() {
			let token = uni.getStorageSync("token")
			uni.request({
				url: this.G_base + '/api/getbankList',
				method:"GET",
				header: {
					'content-type': 'application/x-www-form-urlencoded',
					'Authori-zation': 'Bearer ' + token
				},
				success: (res) => {
					console.log(res);
					this.array = res.data.data
				},
				fail: (err) => {
					console.log(err)
				}
			});
		},
		methods: {
			bindPickerChange: function(e) {
				console.log(this.array[e.target.value].text)
				this.text = this.array[e.target.value].text
				this.index = e.target.value
			},
			regup() {
				let token = uni.getStorageSync("token")
				uni.request({
					url: this.G_base + '/api/UserCart/Add',
					method:"POST",
					data:{
						card_number :this.yhk,
						bank_name:this.text
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation': 'Bearer ' + token
					},
					success: (res) => {
						console.log(res);
						if(res.data.status==200){
							uni.showToast({
								title:"添加成功",
								icon:"none"
							})
							setTimeout(()=>{
								uni.navigateBack({
									delta:1
								})
							},1000)
						}
					},
					fail: (err) => {
						console.log(err)
					}
				});
			},
		}
	}
</script>

<style scoped>
	.xhmc{
		margin: 0 auto;
		width: 300px;
		text-align: center;
		background-color: #FAFAFA;
		padding: 10px;
		border-radius: 50px;
		font-size: 18px;
	}
	.bottom_cont text:nth-child(1) {
		margin-bottom: 7px;
	}

	.bottom_cont text {

		top: 660px;
		width: 154px;
		color: rgba(16, 16, 16, 1);
		font-size: 14px;
		font-family: PingFangSC-regular;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-left: 50%;
		transform: translateX(-50%);
	}

	.wraptop {
		background-color: rgb(255, 255, 255);
		padding-bottom: 30%;
	}

	.content_input {
		display: flex;
		justify-content: center;
		align-items: center;
		flex-wrap: wrap;
		margin-top: 50px;
	}

	.input_cot {
		padding-left: 12px;
		width: 300px;
		height: 54px;
		line-height: 54px;
		border-radius: 20px;
		text-align: center;
		margin-bottom: 22px;
		color: rgba(16, 16, 16, 1);
		font-size: 14px;
		font-family: PingFangSC-regular;
	}

	.bottom_cont {
		margin-top: 32px;
	}

	.btn {

		background: -webkit-linear-gradient(left, #a00000, #e10004, #a00000);
		left: 107px;
		top: 578px;
		width: 164px;
		height: 50px;
		line-height: 20px;
		border-radius: 40px;
		text-align: center;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-left: 50%;
		transform: translateX(-50%);

	}

	.btn text {
		color: #FFFFFF;
		left: 189px;
		top: 593px;
		width: 40px;
		height: 20px;
		font-size: 20px;
		text-align: center;
		font-family: PingFangSC-regular;
	}
</style>